//FG4618_comm.c


#include <stdint.h>
#include <msp430xG46x.h>
#include "FG4618_comm.h"

/* function to configure USCI0A as a UART */
//inputs: none
//outputs: none
void vConfigureUartUsci0(void)
{
    /* Configure USCI0A as a UART */

    /* Configure the port with the reset bit held high */
    UCA0CTL1 |= UCSWRST;
    
    P2SEL |= (BIT4 | BIT5);

    UCA0CTL0 = 0;                   /* 8-bit character */
    UCA0CTL1 = UCSSEL_2;            /* SMCLK */

    /* Set the bit rate registers for 115200 baud */
    UCA0BR0 = 9;
    UCA0BR1 = 0;
    UCA0MCTL = UCBRS_1;

    UCA0STAT = 0;
    UCA0TXBUF = 0;

    UCA0CTL1 &= ~UCSWRST;
}

/* function to configure USCI0B as an I2C port */
//inputs: none
//outputs: none
void vConfigureI2cUsci0(void)
{
    /* Configure USCI0B as an I2C port */
    P3SEL |= (BIT2 | BIT1);
    UCB0CTL1 |= UCSWRST;                    /* Enable SW reset */

    UCB0CTL0 = UCMODE_3 | UCSYNC;           /* I2C Slave, synchronous mode */
    UCB0I2COA = 0x48;                       /* Own Address */
    UCB0CTL1 &= ~UCSWRST;                   /* Clear SW reset, resume operation */
    UCB0I2CIE |= (UCSTPIE | UCSTTIE);       /* Enable STT and STP interrupt */
    IE2 |= UCB0RXIE;                        /* Enable RX interrupt */
}
